#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020/5/11 11:02
# @Author  : yangdy
# @Email   : yangdy@egu360.com
# @File    : 50. Pow(x, n).2020-05-11.py
# @Software: PyCharm

__author__ = 'yangdy'

class Solution:
    def myPow(self, x: float, n: int) -> float:
        # if n == 0:
        #     return 1
        # if n < 0:
        #     x = 1 / x
        #     n = -n
        #
        # def pow(x, n):
        #     ans = 1
        #     while n:
        #         if n & 1 == 1:
        #             ans *= x
        #         n >>= 1
        #         x *= x
        #     return ans
        # return pow(x, n)
        def work(x: float, n: int):
            # print(x, n)
            return x if n == 1 else (1.0 if n == 0 else work(x, n % 2) * (work(x, n//2) ** 2))
        return work(x if n >= 0 else 1/x, n if n >= 0 else -n)


solve = Solution()
x0 = 2.00000
n0 = 10
print(x0, n0)
print(solve.myPow(x0, n0))
